home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / language / plm / readme < prev   
Text File  |  1994-10-24  |  8KB  |  190 lines

  1. $Id: README,v 1.4 1994/04/05 20:33:58 hays Exp $
  2.  
  3. Ah, the wisdom of the ages...
  4.  
  5. Introduction
  6. ------------
  7.  
  8. What you are looking at is a basic (very basic) parser for a PL/M
  9. language.
  10.  
  11. The parser does nothing useful, and it isn't even a terribly wonderful
  12. example.  On the other hand, it appears that no one else has bothered
  13. to publish even this much, before.
  14.  
  15. However, the parser does recognize a language very like PL/M-86,
  16. PL/M-286, or PL/M-386, as best we can determine.
  17.  
  18. All the information used to derive this parser comes from published
  19. manuals, sold to the public.  No proprietary information, trade
  20. secrets, patented information, corporate assets, or skulduggery was
  21. used to develop this parser.  Neither of the authors has ever seen the
  22. source to a working PL/M compiler (or, for that matter, to a
  23. non-working PL/M compiler).
  24.  
  25. Implementation Limits
  26. ---------------------
  27.  
  28. This PL/M parser was developed and tested on a 486DX2/66 clone PC
  29. running Linux.  The C code is written for an ANSI-compliant C
  30. compiler; GCC was used in our testing.  Also, flex and bison were
  31. used, not lex and yacc.  Paul Vixie's comp.sources.unix implementation
  32. of AVL trees was used to implement symbol table lookups.
  33.  
  34. You should expect some problems if you plan on building this parser
  35. with a K&R style C compiler.  Using yacc and/or lex may be
  36. problematic, as well.
  37.  
  38. This parser does not support any of the "dollar" directives of a
  39. proper PL/M compiler.  In fact, it will croak with the helpful message
  40. "parse error".  Thus, implementing include files and compiler
  41. directives is left as an exercise for the reader.
  42.  
  43. The macro facility (aka "literally" declarations) depends on the
  44. lexical analysis skeleton allowing multiple characters of push-back on
  45. the input stream.  This is a very, very poor assumption, but, with
  46. flex, at least, workable for this example.  A real PL/M compiler would
  47. allow literals of unlimited length.  To find the offending code, grep
  48. for the string "very weak" in the file "plm-lex.l".
  49.  
  50. No error recovery is implemented in the parser, at all.
  51.  
  52. There are no shift-reduce conflicts, nor reduce-reduce conflicts.
  53.  
  54. There are a couple of places in the parser where similar constructs
  55. cannot be distinguished, except by semantic analysis.  These are
  56. marked by appropriate comments in the parser source file.
  57.  
  58. The "scoped literal table" implementation depends on Paul Vixie's
  59. (paul@vix.com) public domain AVL tree code, available as
  60. comp.sources.unix Volume 27, Issue 34 (`avl-subs'), at a friendly ftp
  61. site near you.  We use "gatekeeper.dec.com".  The benefits of using
  62. AVL trees for a symbol table (versus, say, hashing) are not subject to
  63. discussion.  We used the avl-subs source code because it is reliable
  64. and easy to use.
  65.  
  66. This grammar has been validated against about 10,000 lines of real and
  67. artificial PL/M code.
  68.  
  69. PL/M Quirks
  70. -----------
  71.  
  72. PL/M has some very interesting quirks.  For example, a value is
  73. considered to be "true", for the purposes of an `if' test, if it is
  74. odd (low bit set).  Thus, the value 0x3 is true, whereas 0x4 is not.
  75. The language itself, given a boolean expression, generates the value
  76. 0xff for true.  [This factoid doesn't affect the parser per se, but
  77. does appear to be the main pitfall for those whose hubris leads them
  78. to translate PL/M to C.]
  79.  
  80. String constants can contain any ASCII value, excepting a single
  81. apostrophe, a newline, or 0x81.  The latter, presumably, has something
  82. to do with Kanji support.
  83.  
  84. To embed a single apostrophe in a string constant, two apostrophes may
  85. be used.  Thus, 'k''s' is a string consisting of a letter k, a single
  86. apostrophe, and a letter s.  Strings are not null terminated, so our
  87. example string, 'k''s', requires just three bytes of storage.
  88.  
  89. PL/M supports a macro language, of sorts, that is integrated into the
  90. language's declaration syntax:
  91.  
  92.     declare Ford literally 'Edsel';
  93.     declare Mercury literally 'Ford';
  94.  
  95. After the above declarations, any instance of the identifier "Ford"
  96. will be replaced with the string "Edsel", and any occurrence of the
  97. identifier "Mercury" will be replaced by the string "Ford", which will
  98. then be replaced by the string "Edsel".  The literal string can be
  99. more complicated, of course.  Only identifiers are subject to
  100. substitution - substitution does not occur inside string constants.
  101.  
  102. Literal macros are parameterless, and obey the scoping rules of the
  103. language.  Thus, it is possible to have different values for the same
  104. macro in different, non-nested scopes.  [Exercise: Why can't you have
  105. different values for literals in nested scopes?]
  106.  
  107. Keywords, of course, cannot be macro names, because they are not
  108. allowed as variable names.
  109.  
  110. PL/M allows dollar signs ("$") to be used inside keywords,
  111. identifiers, and numerical constants.  PL/M is also case insensitive.
  112. Thus, the following two identifiers are the "same":
  113.  
  114. my_very_own_variable_02346
  115.  
  116. m$Y_$$$VeRy_$$O$$$$$W$$$$$$N_varIABLE$$$$$$$$$$_$02$346
  117.  
  118. Loverly, eh?  Obfuscated C, stand to the side.
  119.  
  120. Casting in PL/M (a relatively late addition to the language) is
  121. provided by a motley assortment of functions with the same names as
  122. the basic types to which they are casting, accepting a single argument
  123. of some other (or even the same) type.
  124.  
  125. Note that the EBNF grammar published in what must be considered the
  126. definitive work, _PL/M Programmer's Guide_, Intel order number
  127. 452161-003, Appendix C, is incorrect in several respects.  If you're
  128. interested in the differences, we've preserved, as much as is
  129. possible, the production names of that EBNF in the YACCable grammar.
  130.  
  131. Some known problems with the published, Appendix C, EBNF grammar:
  132.  
  133.      - One of the productions is an orphan, ("scoping_statements").
  134.  
  135.      - unary minus is shown as a prefix operator, and unary plus as a
  136.        postfix operator ("secondary").
  137.  
  138.      - Casting does not appear in the published grammar.
  139.  
  140.      - Nested structures do not appear in the published grammar, and
  141.        the reference syntax for selecting a nested structure member
  142.        is also missing.
  143.  
  144.      - The WORD type is missing from the "basic_type" production.
  145.  
  146.      - The "initialization" production allows the initial value list
  147.        only after the INITIAL keyword, when, in fact, the initial value 
  148.        list may follow the DATA keyword, as well.
  149.  
  150. On the other hand, the precedence of the expression operators is
  151. correct as written in the EBNF grammar, the dangling else problem is
  152. non-existent, and there are no associativity problems, as all
  153. operators associate left-to-right.
  154.  
  155. To complicate matters, the above referenced manual may be out of
  156. print.  A more recent version, which covers the PL/M-386 dialect only,
  157. is _PL/M-386 Programmer's Guide_, Intel order number 611052-001.
  158.  
  159. The latter manual has some corrections, but has some introduced errors
  160. in the EBNF, as well.  The problems with the unary minus and the
  161. "initialization" production are repaired, but the definition for a
  162. "binary_number" is malformed, as are the definitions for the
  163. "fractional_part", "string_body_element", "variable_element", and
  164. "if_condition" productions.
  165.  
  166. We're right, they're wrong.
  167.  
  168. The Authors
  169. -----------
  170.  
  171. Gary Funck (gary@intrepid.com) was responsible for starting this
  172. effort.  He authored the original grammar.
  173.  
  174. Kirk Hays (hays@ichips.intel.com) wrote the lexical analyzer and the
  175. scoped literal table implementation.  He also validated and corrected
  176. the grammar, and extended it to cover documented features not
  177. appearing in the published EBNF.
  178.  
  179. Future Plans
  180. ------------
  181.  
  182. If there is enough interest (or, even if there isn't), Kirk is
  183. planning on producing a PL/M front end for the GNU compiler.  Contact
  184. him at the above Email address for further information.  Donations of
  185. PL/M source code of any dialect (including PL/M-80, PL/M-51, and
  186. PL/M-96)(yes, we already have the Kermit implementations), or a
  187. willingness to be a pre-alpha tester with code you cannot donate, are
  188. sufficient grounds to contact Kirk.
  189.  
  190.